from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `tb_monitor_log` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键Id',
    `deleted` BOOL NOT NULL COMMENT '软删除标记,True无效False有效' DEFAULT 0,
    `create_time` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `summary` VARCHAR(20) NOT NULL COMMENT '接口说明',
    `url` VARCHAR(20) NOT NULL COMMENT '请求地址',
    `method` VARCHAR(20) COMMENT '请求类型',
    `client_ip` VARCHAR(20) COMMENT '客户端IP',
    `payload` JSON COMMENT '请求参数',
    `result` JSON COMMENT '响应结果',
    `status_code` VARCHAR(20) COMMENT '响应码',
    `process_time` VARCHAR(20) COMMENT '响应时间'
) CHARACTER SET utf8mb4 COMMENT='系统日志表';
CREATE TABLE IF NOT EXISTS `tb_monitor_task` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键Id',
    `deleted` BOOL NOT NULL COMMENT '软删除标记,True无效False有效' DEFAULT 0,
    `create_time` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(50) NOT NULL COMMENT '任务名称',
    `func` VARCHAR(50) NOT NULL COMMENT '执行方法',
    `args` VARCHAR(20) COMMENT '位置参数',
    `kwargs` VARCHAR(20) COMMENT '关键字参数',
    `trigger` VARCHAR(50) NOT NULL COMMENT '触发器',
    `start_date` DATETIME(6) COMMENT '开始时间',
    `end_date` DATETIME(6) COMMENT '结束时间',
    `trigger_args` VARCHAR(20) NOT NULL COMMENT '触发器参数',
    `status` SMALLINT NOT NULL COMMENT '状态,1启动2禁用'
) CHARACTER SET utf8mb4 COMMENT='定时任务表';
CREATE TABLE IF NOT EXISTS `tb_system_dept` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键Id',
    `deleted` BOOL NOT NULL COMMENT '软删除标记,True无效False有效' DEFAULT 0,
    `create_time` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(20) COMMENT '部门名称',
    `path` VARCHAR(20) COMMENT '路径',
    `desc` VARCHAR(500) COMMENT '备注',
    `order` INT NOT NULL COMMENT '排序' DEFAULT 0,
    `parent_id` INT NOT NULL COMMENT '父部门ID' DEFAULT 0,
    `active` BOOL NOT NULL COMMENT '是否激活' DEFAULT 1
) CHARACTER SET utf8mb4 COMMENT='系统部门表';
CREATE TABLE IF NOT EXISTS `tb_system_menu` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键Id',
    `deleted` BOOL NOT NULL COMMENT '软删除标记,True无效False有效' DEFAULT 0,
    `create_time` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `title` VARCHAR(20) COMMENT '显示名称',
    `parent_id` INT NOT NULL COMMENT '父菜单ID' DEFAULT 0,
    `type` VARCHAR(100) COMMENT '菜单类型',
    `name` VARCHAR(100) COMMENT '别名',
    `icon` VARCHAR(100) COMMENT '菜单图标',
    `path` VARCHAR(100) COMMENT '菜单路径',
    `redirect` VARCHAR(100) COMMENT '重定向',
    `active` VARCHAR(100) COMMENT '菜单高亮',
    `component` VARCHAR(100) COMMENT '组件',
    `color` VARCHAR(100) COMMENT '颜色',
    `hidden` BOOL COMMENT '隐藏菜单' DEFAULT 0,
    `hiddenBreadcrumb` BOOL COMMENT '隐藏面包屑' DEFAULT 0,
    `fullpage` BOOL COMMENT '整页路由' DEFAULT 0,
    `tag` VARCHAR(100) COMMENT '标签',
    `order` INT NOT NULL COMMENT '排序' DEFAULT 0,
    `apiList` JSON COMMENT '接口权限'
) CHARACTER SET utf8mb4 COMMENT='系统菜单表';
CREATE TABLE IF NOT EXISTS `tb_system_role` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键Id',
    `deleted` BOOL NOT NULL COMMENT '软删除标记,True无效False有效' DEFAULT 0,
    `create_time` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(20) NOT NULL COMMENT '角色名称',
    `alias` VARCHAR(20) COMMENT '别名',
    `desc` VARCHAR(500) COMMENT '角色描述',
    `active` BOOL NOT NULL COMMENT '是否激活' DEFAULT 1
) CHARACTER SET utf8mb4 COMMENT='系统角色表';
CREATE TABLE IF NOT EXISTS `tb_system_user` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键Id',
    `deleted` BOOL NOT NULL COMMENT '软删除标记,True无效False有效' DEFAULT 0,
    `create_time` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `account` VARCHAR(20) NOT NULL COMMENT '账号',
    `realname` VARCHAR(30) NOT NULL COMMENT '姓名',
    `nickname` VARCHAR(30) NOT NULL COMMENT '昵称',
    `avatar` VARCHAR(255) COMMENT '头像',
    `email` VARCHAR(255) COMMENT '邮箱',
    `phone` VARCHAR(20) NOT NULL COMMENT '电话',
    `password` VARCHAR(128) NOT NULL COMMENT '密码',
    `superuser` BOOL NOT NULL COMMENT '是否超级管理员' DEFAULT 0,
    `permission` SMALLINT COMMENT '数据权限',
    `active` BOOL NOT NULL COMMENT '是否激活' DEFAULT 1,
    `last_login_time` DATETIME(6) COMMENT '最后登录时间',
    `last_login_ip` VARCHAR(128) COMMENT '最后登录Ip',
    `dept_id` BIGINT COMMENT '部门'
) CHARACTER SET utf8mb4 COMMENT='系统用户表';
CREATE TABLE IF NOT EXISTS `tb_user_base` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键Id',
    `deleted` BOOL NOT NULL COMMENT '软删除标记,True无效False有效' DEFAULT 0,
    `create_time` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `phone` VARCHAR(20) NOT NULL COMMENT '电话',
    `nickname` VARCHAR(20) NOT NULL COMMENT '昵称',
    `password` VARCHAR(128) COMMENT '密码',
    `avatar` VARCHAR(255) COMMENT '头像',
    `active` BOOL NOT NULL COMMENT '是否激活' DEFAULT 1,
    `last_login_time` DATETIME(6) COMMENT '最后登录时间',
    `last_login_ip` VARCHAR(128) COMMENT '最后登录Ip'
) CHARACTER SET utf8mb4 COMMENT='用户基础表';
CREATE TABLE IF NOT EXISTS `tb_user_auth` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT '主键Id',
    `deleted` BOOL NOT NULL COMMENT '软删除标记,True无效False有效' DEFAULT 0,
    `create_time` DATETIME(6) NOT NULL COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `realName` VARCHAR(20) NOT NULL COMMENT '真实姓名',
    `idCardNum` VARCHAR(20) NOT NULL COMMENT '身份证号',
    `sex` VARCHAR(20) COMMENT '性别',
    `nation` VARCHAR(20) COMMENT '民族',
    `birthday` VARCHAR(20) COMMENT '生日',
    `address` VARCHAR(255) COMMENT '住址',
    `idCardUpPic` VARCHAR(255) NOT NULL COMMENT '身份证正面',
    `idCardDownPic` VARCHAR(255) NOT NULL COMMENT '身份证反面',
    `idCardHandPic` VARCHAR(255) COMMENT '手持身份证',
    `user_id` BIGINT NOT NULL UNIQUE COMMENT '用户'
) CHARACTER SET utf8mb4 COMMENT='用户实名表';
CREATE TABLE IF NOT EXISTS `aerich` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `version` VARCHAR(255) NOT NULL,
    `app` VARCHAR(100) NOT NULL,
    `content` JSON NOT NULL
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `tb_system_role_menu` (
    `menu_id` BIGINT NOT NULL,
    `role_id` BIGINT NOT NULL,
    FOREIGN KEY (`role_id`) REFERENCES `tb_system_role` (`id`) ON DELETE CASCADE,
    FOREIGN KEY (`menu_id`) REFERENCES `tb_system_menu` (`id`) ON DELETE CASCADE,
    UNIQUE KEY `uidx_tb_system_r_menu_id_ad261d` (`menu_id`, `role_id`)
) CHARACTER SET utf8mb4 COMMENT='角色菜单表';
CREATE TABLE IF NOT EXISTS `tb_system_user_role` (
    `role_id` BIGINT NOT NULL,
    `user_id` BIGINT NOT NULL,
    FOREIGN KEY (`user_id`) REFERENCES `tb_system_user` (`id`) ON DELETE CASCADE,
    FOREIGN KEY (`role_id`) REFERENCES `tb_system_role` (`id`) ON DELETE CASCADE,
    UNIQUE KEY `uidx_tb_system_u_role_id_69a733` (`role_id`, `user_id`)
) CHARACTER SET utf8mb4 COMMENT='用户角色表';"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        """
